If you just want to grab one record, or know that you are only expecting one result you can use the following code: <?php // […]
Loop Through Recordset With MySQL and PHP (MYSQLI Connection)
This is the basic syntax required to loop through a MySQL table and output the results <?php // Connect to your database $conn = mysqli_connect(“localhost”, […]
ON DELETE Cascade (Remove child records when parent records deleted)
If you haven’t created the child table you can run the following SQL command: CREATE TABLE ChildTable ( ChildID INT PRIMARY KEY AUTO_INCREMENT, ParentID INT, […]
Loop Through MySQL Fields And Output A Form
This script will loop though all fields in a database and output the name and create a form field with appropriate record value. This is […]
MYSQL: Check User Exists & Grant Privileges On Database
Check if the User Exists SELECT user, host FROM mysql.user WHERE user = ‘your_username’; If the user doesn’t exist, create them first: CREATE USER ‘your_username’@’%’ […]
Remove First Character From A Field In A Database
Assuming we have the following entry in our database: /go/123456 But we require: go/123456 UPDATE `TABLENAME` SET `FIELDNAME` = SUBSTRING(`FIELDNAME`, 2) WHERE `FIELDNAME` LIKE `/%`;
Replace String In Database Field
The following code will replace a string in a database field UPDATE `TableName` SET `DatabaseField` = REPLACE(`DatabaseField`, ‘OldString’, ‘NewString’) WHERE `DatabaseField` LIKE ‘%OldString%’;
Rename SQL Table
If you wish to rename a SQL table use the following code: ALTER TABLE table_name RENAME TO new_table_name;
Add an Index to a MySQL Table
An index speeds up the serving of data by allowing you to quickly find data in a table without having to go row by row […]
Copy MYSQL Table Structure and Import Specific Columns
This code will allow you to copy the table structure from an existing table into a new one and then copy data from specific columns […]