Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Is there a way by which I can make the result set returned by PDO same as the data set returned by the legacy mysql functions?
Actually, all the files in my application call a function to execute any SQL query. Currently that function uses old mysql functions. I want to change it to PDO in that single function, effectively changing to PDO over the whole application.
Hence, I need a way so that the format of the result coming out is the same as the old mysql functions.
If you mean the result set resource returned by mysql_query, then: no. Resources are specific to the extension that defines them and are meaningless to anything else. PDO returns an object, mysql_query a resource; that's apples and oranges.
If you mean an array you'd build with mysql_fetch_assoc and PDOStatement::fetch, then: of course, you can make them look identical if you bother to do so.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
as we all know,there is a data type 'resouce' in php!I sometimes can encounter this data type!but I have some problems about this type!
when I have a db connect,I print the data type,it displays"resource(4, mysql link)",
when I create a image,I print the data type,it displays "resource(2, gd)"
i want to know what the number eg.'4','2' means in the "()".
sorry for my bad englis!
When you see resource(4, ...) what that means is that PHP is keeping a reference to a more complex object that isn't a normal PHP object, and thus can't be manipulated directly. It's typically used by libraries that interface with non-PHP code (such as database client libraries and the GD library).
The number is simply the ID number of that particular external object.
These resources are managed by the external library and only really given to PHP as an indirect reference; they only have meaning to the library code that created them.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is it usefull to convert all my PHP codes from mysql to mysqli?
I mean will mysql be deleted? And is there a tool that converts my codes to mysqli? Or do I just have to change all i.e. mysql_query to mysqli_query?
Is it useful?
Yes, read Why shouldn't I use mysql_* functions in PHP? So if you plan on running your code in years to come, you should consider it.
Is there a tool?
This tool if often mentioned but I have never tried it and I think you would learn more by doing it manually. It also seems more complicated than doing it by hand if you're a beginner.
Changing all your mysql_query() function calls to mysqli_query() is not enough. The mysqli_query function requires that you pass a link identifier as the first argument wheareas with mysql_query "If the link identifier is not specified, the last link opened by mysql_connect() is assumed."
And of course it's not just the mysql_query calls you would have to change, but all mysql_* calls.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I use the method or function mysql_num_rows() in my php code, it worked great and had no issues. I later just changed my web host. I created a new database that is identical to my old one. I changed all the information to access the database and am getting access to the new database but it is throwing an error once the code reaches mysql_num_rows. Why am I getting an error for mysql_num_rows? The results are suppose to be 0 when the function is ran because I have no information in my new database, but I also added information just so I didn't get a 0 and it is still giving my an error. Why?!!!!
Sounds like you've moved to a server with a newer version of PHP - mysql functions are deprecated, use mysqli (and convert the rest of your database functions to mysqli):
http://au1.php.net/manual/en/mysqli-result.num-rows.php
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
<?php echo mysql_real_escape_string('tientrer') ;?>
The above code is return an empty string in one server but is working fine in other servers. Why is it so?
Wildly random guess:
You are not connecting to a database using mysql_connect. mysql_real_escape_string needs a database connection to do its job (because you are escaping for the database; you are escaping this for a database query, right?!). If no connection exists yet, it'll try to establish one automatically using a standard username and password. On one server this standard password works, on another it doesn't.
you are escaping a string ?
you mean maybe like that
<?php echo mysql_real_escape_string($tientrer) ;?>
to escape the variable tientrer if its a variable.
EDIT:
then maybe the server which not working maybe the mysql is deprecated there , try change to mysqli or pdo
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a PHP script that displays data read from a MySQL database. I want to filter the output to only show rows where two columns contain specific values. How do I do this?
Add a WHERE clause, e.g., WHERE column1 = 'specific-value1' AND column2 = 'specific-value2'
Here's a link to MySQL's SELECT syntax:
http://dev.mysql.com/doc/refman/5.1/en/select.html
(and in German):
http://dev.mysql.com/doc/refman/5.1/de/select.html
no idea why you are posting in german on an english site and then translating it to english. But what you need to do is something like "select * from table where column1='val' and column2='val'". Though it sounds like you have a large set of data pulled off already and you want to filter that. I don't see why you shouldn't just query what you need from the database instead of pulling everything off and then filtering.