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');