Jump to content

Recommended Posts

I suggest you start with the basics before jumping to any special features. There seems to be a lot of confusion here. You said you used mysqli, you've actually used the old ext/mysql extension, and now you've appearently switched to PDO.

 

If you want to go with PDO, learn how to establish a connection first.

Just gave the above code example of one of dozens that I have tried, this seemed the simplest to try and convey what I was trying to achieve. I'm only trying PDO on the suggestion of Benanamen, but give me a simpler way if there is one and I will use that. Newbie, 4 years since I last wrote any code.

What you don't seem to understand is that accessing a database requires a complete library. This isn't just one line of code which you can copy and paste. You have to establish a connection, execute a query (or in your case a prepared statement) and ultimately fetch data from the result set.

 

So the first step is to choose a library. The mysql_* functions you were using previously are hopelessly outdated and have already been removed from the current PHP version. Nowadays were're using PDO or mysqli. PDO is a good choice.

 

Now you need to learn PDO. We can't do that for you. You need to actually read and understand the tutorial referenced by benanamen.

Edited by Jacques1

I said what I said. Now you need to read and understand it.

 

I know you're in a hurry, and reading longer texts is difficult in the era of 140-character Tweets. But if you want to write any code whatsoever, you have to be able to absorb information. Programming isn't copy-and-paste.

Jacques1, yes I will do, and thanks for everything. But no, I'm not in a hurry, this is a personal project of no great importance. It was such a simple query that I expected there might be a simple answer. I am returning to coding after a 4 year gap, I was a newbie then and still am now, so will endeavour to learn the current correct methods.

Thanks again.

Edited by Snewzzer

This isn't about one query, it's about an entire database library. You cannot randomly insert a PDO or mysqli method call in the middle of your code. You choose one library, and then all database operations now and in the future have to be implemented with that library. You may even have to rewrite large parts of your current code.

 

Forget about the single value stuff. This is about all of your queries.

Jacques1, if I had to rewrite ALL of my code it wouldn't take too long! It consists of only two very short files which I only began a few nights ago. So I can throw everything out and start again... which I am doing now, starting with the php manual. Thanks.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.