$query="CREATE TABLE student ( id int(2) NOT NULL auto_increment, name varchar(50) NOT NULL
default '', class varchar(10) NOT NULL default '', mark int(3) NOT NULL default
'0', PRIMARY KEY (id) ) TYPE=MyISAM";
We have stored the sql create query in a variable $query and we will pass this as a
parameter to the function like below.
$rt=$connection->query($query);
The above command will execute php_mysqli() the query ( stored in variable $query) and we can
check the status of the query ( successful or not ) by checking the value of the variable $rt. $rt will be true if the query is successfully executed or it will return false. We will use php if command to check the status of the query.if($rt){echo " Command is successful ";}
else
{echo "Command is not successful ";}
So from the above line we can know that the query has worked or failed. But we will
not come to know about the error if the database has some error and the query has failed. To get the error
message we have to use another function mysqli_error() to print the error message
returned by MySQL database after executing the query. Here it is how to print
the error message.
echo mysqli_error();
The above line will print the error returned by mysql database if the query fails to
execute. You can read more on mysql error here.
$query="UPDATE student SET class='Five'";
if ($connection->query($query)) {
echo "Records Updated";
}else{
echo $connection->error;
}
Before executing the above code we must connect to mysql database by using mysqli connection string.
vexatiousjones | 04-02-2016 |
Im getting a No Database Selected error when using this code. Im using PDO connection string linked aboe. Any Suggestions? |
smo1234 | 06-02-2016 |
YOu need to connect to database and select database. Read the connection string link available here. |
Ann Ekpe | 26-03-2017 |
Good day . please I need your assistance.I am currently designing a webpage with members signing in and having a dashboard.I want to be able to send data from the database to each particular member , so anytime they login to the website they can view the data... Urgent HELP |
smo1234 | 26-03-2017 |
You can store the message in a table and display inside login area, that is when member login is completed this message can be displayed. The message can be managed by adding or updating new message etc. Knowledge of any scripting language and Database handling is required. |