Jump to content

Mysql Scalar?


Nodral

Recommended Posts

Hi All

 

I've a question regarding php and mysql database interrogation.  Is there a way of applying a scalar database call from php, rather than having to return values in an array?

 

For example if I know there is only 1 value in a DB table which matches a select statement, do I have to return it with the following or is there another function which will save me using arrays?

 

$sql="SELECT name FROM users WHERE id = 10";
$sql=mysql_query($sql);
$row=mysql_fetch_array($sql);

 

This would then give me $row['name'] to work with.

Is there a way of doing this?

Link to comment
Share on other sites

The simple answer is no. The interfaces are designed to return arrays because it is far more common to retrieve more than one field form a database.

 

If you want to abstract this further yourself, php allows you to create your own functions.

Link to comment
Share on other sites

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.