PHP code example of stnc / pdo-database

1. Go to this page and download the library: Download stnc/pdo-database library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stnc / pdo-database example snippets



  define('DB_TYPE', 'mysql');
  define('DB_HOST', 'localhost');
  define('DB_NAME', 'wordpress');
  define('DB_USER', 'root');
  define('DB_PASS', '');
  

/* //use 1 
use Stnc\Db\MysqlAdapter ;
$db = new MysqlAdapter();
*/

/* //use 2
use Stnc\Db\MysqlAdapter as dbs;
$db = new dbs();
*/


//use 3
$db = new Stnc\Db\MysqlAdapter();
$tableName = 'users';

$q = "SELECT * FROM ".$tableName;
$array_expression = $db->fetchAll ( $q );
foreach ( $array_expression as $value ) {
	echo  $value ['name'];
	echo '<br>';
}

$tableName = 'wp_options';//wordpress 
$q = "SELECT * FROM ".$tableName;
$array_expression = $db->fetch ( $q );
echo $array_expression ['name'];
//or 
$q = 'SELECT * FROM '.$tableName.' where option_name="siteurl" ';
$array_expression = $db->fetch ( $q );
print_r ($array_expression);
echo $array_expression ['option_name'];



$q = "ALTER TABLE users MODIFY COLUMN user_id  int(11) NOT NULL AUTO_INCREMENT FIRST";
$db->query ( $q );

$data = array (
		'name' => "john",
		'lastname' => "carter",
		'status' => 1,
		'age' => 25 
);


$db->insert ( $tableName, $data );

$data = array (
		'name' => "john",
		'lastname' => "carter",
		'status' => 1,
		'age' => 25 
);
$where = array (
		'user_id' => 1 
);
$db-> update ( $tableName, $data, $where );

$where = array (
		'user_id' => 1 
);

return $db->delete ( $tableName, $where );

$db->lastID();

$db->tableName=$tableName;
$db->where('id', '=', 1)->update2(['username' =>'selman sedat']);