If you open the connection using a PDO function, you need to carry on using PDO functions to run queries, recover results - you canât use a mysqli function for that, you canât mix the two.
Exactly as the error message says, your mysqli function requires a mysqli connection object as the first parameter, not a PDO connection.
Have you read through any of the PDO documentation? PDO is a complete library. As a quick-start, Iâd do this:
$myTableInsert=("INSERT INTO myTable (myNumeric)
VALUES (1234)");
$myTableInsertEXE=$conn->query($myTableInsert);
or something like that. I must admit that by sheer force of habit, I tend to prepare every statement, which might be a bit over the top for your particular example. As soon as you need to put a variable into the query, though, thatâs when you need to prepare rather than just concatenate it into the string.
Thatâs because you have a lot of problems with your spacing. You need to stop making all of those random spaces because itâs going to keep throwing you that error. Whenever that error happens, it usually means youâre not putting in the right syntax. All of your PDO constants are incorrect. You need to go back and fix them. The double colons should not have any spaces nor the PDO constants on both sides of the colons.
Youâre going to have a problem here too as itâs incorrect. Should be the arrow operator and not the pass by reference operator.
No, what I meant was, the article on the site I linked to used âutf8mb4â,but youâd changed that to âutf36mb4â and I wondered why you had done that. I see youâve changed it back to utf8 now.
It will, see the typo in this line:
$stmt = $pdo = query ('SELECT myNumeric FROM myTable');
Youâve had quite a few similar typos, perhaps take a minute to go over your code and check for things like that. Compare it to your code in post #7 to see the difference.
phpmyadmin which I downloaded recently has the option with utf8, utf16, and utf36 when I created the database âmyDBâ.
When I made PDO connection code, I did choose utf36 because I guessed this might be the newest and utf36 might also be the newest.
That was the reason why I had done that.
Anyway I am back to âutf8â not.
$stmt = $pdo = query ('SELECT myNumeric FROM myTable');
// as I change the above
// to the below.
$stmt = $pdo-> query ('SELECT myNumeric FROM myTable');
It produces the following notice. This was why I tried to change â->â to â=â on line 26.
By the way,
I am not accustomed to the code â->â.
What does it mean by â->â in the code below?
Could you rephrase the code above in English?
Could you rephrase the code above in English?
Could you rephrase the code above in English?
And what is the full word of $stmt which is from https://phpdelusions.net/pdo#dsn
Does it, I guess, stand for âstatementâ?
-> is used in object-oriented programming - in this case, $PDO is an object of a particular class, and query is a function within that object. You are using -> to link the query to the object.
(Seems from the above that I canât really explain it in English after all. Iâm sure someone will be along to point you to a guide to object-oriented programming soon.)
Itâs just a name, you could call it anything (with some exceptions) but itâs always a good idea to have variable names with some meaning. I usually call my database connection $dbc for example - short enough to not be a pain to type out, but enough there to remind me what it is.
It has a lot of names, but I usually call it the âarrowâ operator. Like @droopsnoot said, itâs for accessing objects and methods. Some languages like C++ uses this for specific accessors like pointers. PHP is one of those languages that uses it for its primary object-orientation whereas other languages use the âdotâ operator.
The connection itself starts when you instantiate the instance of that class. So it would be #2. The stuff in your #1 is only setting a string so that you can later use it in your connection.
With the code below, are the statements below both (1) and (2) correct?
(1) â$pdoâ in the code below is an object.
(2) â$queryâ in the code below is a function.
$stmt = $pdo -> query ('SELECT myNumeric FROM myTable');