Skip to content

Commit

Permalink
Updating a mysqli method.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelfaj committed Mar 1, 2018
1 parent e53ec8c commit 5e88afd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
102 changes: 51 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,72 +28,72 @@ require_once('/includes/class_db.php');
## Examples

Initializing
```
```php
<?php
include ('class_db.php');
include ('class_db.php');

$db = new db(array(
'host' => 'localhost' , // string - Host of Connection.
'user' => 'username' , // string - Database's User.
'password' => 'mysecretpass' , // string - User's Password.
'database' => 'myapplication' , // string - Default Database name.
'db_type' => 'mysql' , // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
));
$db = new db(array(
'host' => 'localhost' , // string - Host of Connection.
'user' => 'username' , // string - Database's User.
'password' => 'mysecretpass' , // string - User's Password.
'database' => 'myapplication' , // string - Default Database name.
'db_type' => 'mysql' , // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
));

$sql = new query($db);
$sql = new query($db);
```

Doing a simple query passing it as text:
```
```php
<?php
include ('class_db.php');
$db = new db(array(
'host' => 'localhost' , // string - Host of Connection.
'user' => 'username' , // string - Database's User.
'password' => 'mysecretpass' , // string - User's Password.
'database' => 'myapplication' , // string - Default Database name.
'db_type' => 'mysql' , // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
));
$sql = new query($db);
$sql->exec("SELECT * FROM users");
var_dump($sql->query);
include ('class_db.php');

$db = new db(array(
'host' => 'localhost' , // string - Host of Connection.
'user' => 'username' , // string - Database's User.
'password' => 'mysecretpass' , // string - User's Password.
'database' => 'myapplication' , // string - Default Database name.
'db_type' => 'mysql' , // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
));

$sql = new query($db);
$sql->exec("SELECT * FROM users");
var_dump($sql->query);
```

Doing a select without write one single character of SQL:
```
```php
<?php
include ('class_db.php');
$sql = new query(array(
'host' => 'localhost' , // string - Host of Connection.
'user' => 'username' , // string - Database's User.
'password' => 'mysecretpass' , // string - User's Password.
'database' => 'myapplication' , // string - Default Database name.
'db_type' => 'mysql' , // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
));
$sql->table('users');
$sql->limit(array(0,10));
include ('class_db.php');

$sql = new query(array(
'host' => 'localhost' , // string - Host of Connection.
'user' => 'username' , // string - Database's User.
'password' => 'mysecretpass' , // string - User's Password.
'database' => 'myapplication' , // string - Default Database name.
'db_type' => 'mysql' , // string - Type of Database. (It can be: 'mysql', 'mysqli' , 'mssql' , 'sqlserv' , 'pgsql').
));

$sql->table('users');
$sql->limit(array(0,10));

var_dump($sql->select());
var_dump($sql->select());
```

Selecting and updating a user without write one single character of SQL:
```
$sql = new query($db);
$sql->table('users');
$sql->where(
array('id' , $_POST['id']),
array('email' , $_POST['email'])
);
$sql->order('id','DESC');
$sql->limit(1);
if( $sql->select()->have_rows ){
$sql->update(array('active' => 0));
}
```php
$sql = new query($db);
$sql->table('users');
$sql->where(
array('id' , $_POST['id']),
array('email' , $_POST['email'])
);
$sql->order('id','DESC');
$sql->limit(1);

if( $sql->select()->have_rows ){
$sql->update(array('active' => 0));
}
```

## License
Expand Down
8 changes: 4 additions & 4 deletions class_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function __construct($connection = array(), $debugmode = false, $connect_
* -> 'elapsed_time' # int - Elapsed time between start and finish of query.
*/
public function exec($sql='', $result_comparison_signal = '>', $fetch_all_rows = true){
if(empty($sql)) $sql = $this->sql;
if(empty($sql)){ $sql = $this->sql; } else { $this->sql = $sql; }
if(empty($sql)) return false;

$this->info['start_date'] = date('Y-m-d H:i:s');
Expand Down Expand Up @@ -379,7 +379,7 @@ public function select($fields = array('*'), $result_comparison_signal = '>=', $

/**
* Executes a new INSERT query.
* @param string $insert (optional) fields to get.
* @param string $insert Fields and values to insert.
* -> Example: array('id' => 1,'register_date' => date('Y-m-d H:i:s'))
* @param boolean $addslashes If true it'll quote strings with slashes on $insert values.
* @param boolean $literal If false it'll add, IN THE QUERY, quotes before and after the values.
Expand Down Expand Up @@ -407,7 +407,7 @@ public function insert($insert, $addslashes = true, $literal = false, $result_co

/**
* Executes a new UPDATE query.
* @param string $insert (optional) fields to get.
* @param string $update Fields and values to update.
* -> Example: array('name' => 'Samuel Faj','register_date' => date('Y-m-d H:i:s'))
* @param string $safemode If true it will not execute the query if there aren't where conditions.
* @param boolean $addslashes If true it'll quote strings with slashes on $insert values.
Expand Down Expand Up @@ -640,7 +640,7 @@ public function num_rows(){
if(is_resource($this->obj_query)) $rows_number = mysql_num_rows($this->obj_query);
break;
case 'mysqli':
$rows_number = $this->obj_db_connection->num_rows();
if(is_object($this->obj_query)) $rows_number = $this->obj_query->num_rows;
break;
case 'mssql':
if(is_resource($this->obj_query)) $rows_number = mssql_num_rows($this->obj_query);
Expand Down

0 comments on commit 5e88afd

Please sign in to comment.