PHP
Trying to use php to manage the database via website.
It should be easy but ???
$dbname='nutrition';
$dbuser='~~~~~~~~~~~~~~~';
$dbhost='localhost:port_number';
$dbpass='###################';
$connect= new mysqli($dbhost, $dbuser, $dbpass, $dbname);
//check for errors
if ($connect->connect_errno) {
echo "Failed to connect to MySQL: " . $connect->connect_error;
}
Problems using old code. I had to use the Object Orientated Programming option of new mysqli() and append the port number to $dbhost
August 8th
Problem accessing a value by using a php variable [$cat_id]
Here is the code
"SELECT name FROM category WHERE id='".$cat_id."'";
and here is where I found the syntax, after some 16 hours ??
msdk.com/php/use-php-variable-in-a-select-like-query
August 9th
08:00 Getting to grips with the new mysqli and have populated category list ✓
id=’".$cat_id."‘
id=something
but as the something is not plain characters it has to go in single quotes
id=’something’
as the something is a variable is has to be converted to simple characters which it can do
1. Assume $cat_id is text
2. but as it isn’t directly it has to go inside a concatenation of [text . variable .text]
hence the use of the double quotes to allow the concatenation to explode
3. We get ” the value of the variable”