Update
DB-php
Free Functions To Connect To The Database ( Mysql ) For Php Programmers
This Version : 2.0
connect to database
connect(string $dbname,string $username_db,string $password_db,string $host = 'localhost');
This Function :
connect('dbName','myuser','passworduser');
Php :
$Option = [
PDO::ATTR_PERSISTENT => TRUE,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND =>'SET NAMES utf8',
PDO::ATTR_EMULATE_PREPARES => false
];
$pdo = new PDO("mysql:host=localhost;dbname=dmn_nm;charset=utf8", "myAdmin" , 'abcdefgh1234' , $Option );
SQL Select Examples
select * from db where id = 10 limit 3
PHP :
$select = select('*','db',['id'=>10],'limit 3');
execute :
array (size=2)
'count' => int 3
'fetchAll' =>
array (size=3)
0 =>
array (size=7)
'id' => int 17
'step' => string 'support' (length=7)
'chat_id' => int 1212
'Cash' => null
'vip' => int 0
'grade' => int 0
'Download' => int 0
1 =>
array (size=7)
'id' => int 18
'step' => string 'NewUser' (length=7)
'chat_id' => int 1016239559
'Cash' => null
'vip' => int 0
'grade' => int 0
'Download' => int 0
2 =>
array (size=7)
'id' => int 19
'step' => string 'NewUser' (length=7)
'chat_id' => int -663757927
'Cash' => null
'vip' => int 0
'grade' => int 0
'Download' => int 0
select * from db
PHP
select('*','db');
SQL LIKE Examples
SELECT * FROM Customers
WHERE CustomerName LIKE 'a%';
PHP
This Update : 2.0
like('*','Customers',[
'CustomerName'=>'a%'
]);
MIN() Example
SELECT MIN(Price) AS SmallestPrice
FROM Products;
PHP
select('MIN(Price) AS SmallestPrice','Products');
SQL INNER JOIN Example
This section will be updated later
SELECT Orders.OrderID, Customers.CustomerName FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
PHP
select('Orders.OrderID, Customers.CustomerName','Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID');
SQL insert Example
sql :
insert into table (one,tow,there) values ('one','tow','there')
php :
insert('table',['one'=>'one','tow'=>'tow','there'=>'there']);
execute => 0 or 1 query insert('table',['one'=>'one','tow'=>'tow','there'=>'there']);
:
insert into table (one,tow,there) values (?,?,?)
The content is then filled with prepare and bindValue
SQL delete data
deleted(string $table ,$where = "None",string $other = null);
SQL:
DELETE FROM one WHERE p = 12
PHP :
deleted('one',['p'=>12]);
SQL update Example
sql:
update tb set id = '12' where name = '14'
PHP :
update('tb',['id'=>12],['name'=>14]);
execute : 0 or 1 If execute is equal to 0, it means that the update has not been done
SQL Created New Table
table(string $table,$column);
sql :
CREATE TABLE accounts (
id int
);
php :
table('accounts',['id'=>'int']);
execute => 0 or 1
SQL Set unique column
unique(string $table,$column);
SQL :
ALTER TABLE articles
ADD UNIQUE (slug)
php:
unique('articles',['slug']);
SQL Set primary Key
primary(string $table,$column);
SQL :
ALTER TABLE accounts
ADD PRIMARY KEY (token);
php :
primary('accounts',['token']);
Drop Table & column Exsample
drop($table,array $columns = []);
SQL Drop column:
ALTER TABLE table
DROP COLUMN column;
PHP Drop column:
drop('table',['column']);
SQL Drop Table
DROP TABLE a,b;
PHP Drop Table :
drop(['a','b']);