Search easily in a Mysql database using PHP
It takes out some of the pain of playing with mysql in PHP, letting you write less code and go faster!
First you have to include or require the class BDManager
include 'path/to/BDManager.php';
Now you have to set the host, username, password and database you want to use.
include 'path/to/BDManager.php';
$bd = new BDManager('localhost','root','','your-database-name');
And you are good to go!
#Examples
Given the following table called 'users' in MySql, we are going to make a SELECT, UPDATE, DELETE.
id | name | telephone | |
---|---|---|---|
1 | Johny | [email protected] | +011354987 |
2 | Katherine | [email protected] | +011324786 |
- Select * from users, and then echo all their names
$users = $bd->query('select * from users');
for($i=0; $i<count($users); $i++){
echo $users[$i]['name'];
}
- If you want to connect your results as a Web Service, you could just simply do:
$users = $bd->query('select * from users');
header('Content-Type: application/json');
echo json_encode($users);
you would get:
[
{
"id":1,
"name":"Johny",
"email:"[email protected]",
"telephone":"+011354987"
},
{
.... other results
}
]
- Insert a user, and verify if it was done
$bool = $bd->insert("insert into users (id,name,email,telephone) values (3,'Juan','[email protected]','+57351684886')");
if($bool){
//do something
}else{
//throw error or whatever
}
.... more examples coming soon!
#License Use BDManager as you want. You can modify it, distribute it, use it for commercial purposes .. well you name it.
By Juan Camilo Guarin Peñaranda http://otherwise-studios.com