1. Go to this page and download the library: Download entomb/obj_mysql 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/ */
entomb / obj_mysql example snippets
//nclude("bin/OBJ_mysql.php");
//configuration array
$config = array();
$config["hostname"] = "YOUR_HOST";
$config["database"] = "YOUR_DATABASE_NAME";
$config["username"] = "USER_NAME";
$config["password"] = "PASSWORD";
//other configurations
$config["port"] = "PORT"; //defaults to 3306
$config["charset"] = "CHARSET"; //defaults to UTF-8
$config["exit_on_error"] = "TRUE|FALSE"; //defaults to true
$config["allow_logging"] = "TRUE|FALSE"; //defaults to true
//class instantiation
$db = new OBJ_mysql($config);
$Result = $db->query("SELECT * FROM users");
$Users = $Result->fetchALL();
$db->insert( String $Table, Array $Data); //generates an INSERT query
$db->replace(String $Table, Array $Data); //generates an INSERT OR UPDATE query
$db->update( String $Table, Array $Data, Array $Where); //generates an UPDATE query
$db->delete( String $Table, Array $Where); //generates a DELETE query
$new_user_id = $db->insert('users', array(
'name' => "jothn",
'email' => "[email protected]",
'group' => 1,
'active' => true,
)
);
if($new_user_id){
echo "new user inserted with the id $new_user_id";
}
$Result = $db->query("SELECT * FROM users WHERE id_user = ? AND active = ? LIMIT 1",array(11,1));
if($Result){
$User = $Result->fetchArray();
print_r($User);
}else{
echo "user not found";
}
$Result = $db->query("SELECT * FROM users");
$AllUsers = $Result->fetchAll();
$Row = $Result->fetch(); // Fetch a single result row as defined by the config (Array or Object)
$Row = $Result->fetchArray(); // Fetch a single result row as Array
$Row = $Result->fetchObject(); // Fetch a single result row as Object
$Data = $Result->fetchAll(); // Fetch all result data as defined by the config (Array or Object)
$Data = $Result->fetchAllArray(); // Fetch all result data as Array
$Data = $Result->fetchAllObject(); // Fetch all result data as Object
$Data = $Result->fetchColumn(String $Column); // Fetch a single column in a 1 dimension Array
$Data = $Result->fetchArrayPair(String $key, String $Value); // Fetch data as a key/value pair Array.
$db->get() // Alias for $db->fetch();
$db->getAll() // Alias for $db->fetchAll();
$db->getObject() // Alias for $db->fetchAllObject();
$db->getArray() // Alias for $db->fetchAllArray();
$db->getColumn($key) // Alias for $db->fetchColumn($key);
$Result = $db->query("SELECT * FROM users");
//using while
while( $row = $Result->fetch() ){
echo $row->name;
echo $row->email;
}
//using foreach
foreach( $Result->fetchAll() as $row ){
echo $row->name;
echo $row->email;
}
print_r($db->log());
if( $db->errors() ){
echo $db->lastError();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.