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

Install LAMP Stack on AWS EC2 with Amazon Linux from Start to Finish

How to Install LAMP Stack on AWS EC2 with Amazon Linux Here are quick steps to install LAMP Amazon EC2 Access your EC2 instance via SSH or Instance Connect from terminal Start by updating yum: yum update Verify PHP doesn't currently exist: php -v Install PHP if it couldn't be found: sudo yum install php Verify php is installed: php -v Install various important php extensions: sudo yum install php-fpm php-mysqli php-json php-deve Install Apache web server and wget: sudo yum install httpd wget Install MySQL: sudo yum install -y mariadb-server Configure your PHP.ini file and add other required extensions #Update Linux Packages sudo yum update -y #Install PHP sudo yum install php #Check PHP version php -v #Install important PHP extensions sudo yum install php-fpm php-mysqli php-json php-deve #Install Apache Web Server and wget sudo yum install httpd wget #Install MariaDB server sudo yum install -y mariadb-server The article…

read more

How to Store a PHP Array in MySQL

Store Array in MySQL PHP
Save a PHP array in mySQL column This article explores how to save PHP arrays in MySQL. MySQL is an open-source relational database management system that allows you to store data in rows and columns. SQL stands for Structured Query Language for manipulating and retrieving data from SQL databases. Know more about MySQL. Before You Read! The article requires you to connect to your MySQL database with PHP, create a table and connect to it in PHP. If you’re not familiar with all these consider learning it from w3schools. Here we just focus on different ways of storing arrays in MySQL PHP. Storing Arrays in a Normalized Table Employees Table You need to create an employee table at your end if you’re trying out the examples in the article. For your convenience, here’s the SQL table creation code for you. CREATE TABLE EMPLOYEES_TABLE ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,…

read more