5 PHP mysqli_query Code Examples to Learn SQL in 2023

Using PHP mysqli_query The following are the common steps while using the PHP mysqli_query() function to execute queries on a SQL database server. Create a connection to the server using mysqli_connect() Specify a SQL query string. Call mysqli_query() with the connection object and SQL string. Consume the return value. ?php $servername = "localhost"; $username = "fuelingphp"; $password = "fuelingphp"; $database = "fuelingphp"; // Creates a connection $connection = mysqli_connect($servername, $username, $password, $database); // Checks if the connection has been established. if (!$connection) { die("Connection failed: " . mysqli_connect_error()); } // SQL query to create a new table $sql = "CREATE TABLE articles ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, title VARCHAR(30) NOT NULL, category VARCHAR(30) NOT NULL )"; //Executes query if (mysqli_query($connection, $sql)) { echo "New table articles has been created"; } else { echo "Error: " . $sql . " : " . mysqli_error($connection); } // SQL query to…

read more