Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm currently developing an auditing web app using PHP and MySQL. The app was developed locally using XAMPP without any issues. However after deploying it to my host's servers one of the php files that accesses the database using PDO started to generate a 500 internal server error. After some debugging the fetch() function was found to be the source.
// works
$sql="INSERT INTO subsection (section_id) VALUES (:section_id)";
$query=$db->prepare($sql);
$query->execute(array(':section_id'=>$section_id));
// doesn't work
$sql="SELECT audit_id FROM audit
WHERE audit_id < :audit_id
ORDER BY audit_id DESC LIMIT 1";
$query=$db->prepare($sql);
$query->execute(array(':audit_id'=>$audit_id));
$prevAuditId=$query->fetch()[0]; // <-- error generated here
phpinfo() reveals that the host's servers are running PHP version 5.33 and PDO support is enabled. So to summarise, the web app works locally on a XAMPP installation and when hosted PDO appears to function except for the fetch method().
Any clarification on this issue would be greatly appreciated.
The problem is that you're using PHP 5.3, but the array-dereferencing syntax you've used is only allowed from PHP 5.4 and up.
Here's your code:
$prevAuditId=$query->fetch()[0];
The problem is nothing to do with the PDO call, it's caused by the [0] at the end.
Getting an array element from a function call like this is called "dereferencing" the array. PHP 5.3 doesn't support this. If you need to stick with PHP 5.3, you'll have to split it out into two lines:
$auditRecord=$query->fetch();
$prevAuditId=$auditRecord[0];
Alternatively, you could upgrade your server to PHP 5.4 (or later), where your original syntax is valid.
Hope that helps.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm currently working on a website for a client, but this website is running PHP version 5.2.17.
Can anyone recommend the best way to tackle this? I've experience in HTML/CSS/JS/JAVA with a basic understanding of PHP.
I'm thinking of rebuilding the website with a HTML5 framework and basically dumping this on top of the old PHP pages, integrating the MySQL database and passing through the links to not lose SEO, but ultimately do worry it may affect the site...
I've tried running a WAMP server but as it only goes as low as version 5.3 I get constant errors and the page displays without the CSS and has words overlapping etc.
Images attached.
The errors you are encountering are to do with files which are being included not being found. Check through the code and identify the files that are being requested, then locate those files and correct the file paths, if the files can not be restored then remove the include statements entirely or comment them out, make sure they have been removed from evrrywhere.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my project simply I want to run local application as netbeans or word document installed in my computer on click of a link? Is it possible ? If yes how am I to do it? If no why it's not possible.
Thanks in advance.
You can link to a PHP script and then in this script use exec() to run your application.
<?php
exec('path/to/your/app.exe -possibleparam -param2');
/* EOF */
I don't know if it is that what you are looking for:
http://www.php.net/manual/en/function.exec.php
exec will execute the app in the machine where the php is installed (so your server).
If you mean that the php should open an app on the user pc while he's surfing on your site, no.
The only way to to this is an NPAPI plugin. And use Javascript, not PHP.
PHP runs on the server. It has no control over the client. This is by design. If web pages could run programs on the client computer then it would be abused to an unlimited degree, for spam, viruses, and junk.
You can use the exec function to run a program on the server. If your server and client happen to be running on the same local computer, then this will do what you want.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Am currently working on a website(html 5) that calculate the expenses for the user, after the calculation, user has to save it as report for future purposes. So i wanna know if there is anyway to connect my website(html5) to database using phpadmin.
thankyou
html5 doesn't connect to SQL (phpmyadmin), but php does :)
html5 is for delivering static documents. To do things such as connecting to databases, you need a server side language like php.
html5 generally means javascript and modern html features. Neither of these things have anything to do with PHP. However, you can write php inside your html5 web page, and connect to a database from there.
How exactly you would go about doing this depends on what OS you are running, but if you want to start using php and SQL together with phpmyadmin, you'll need to setup an apache server, and install php and mysql.
A full tutorial on it is out of the scope of a stack overflow post, but I suggest researching LAMP, XAMPP, and WAMP keywords. By installing these, depending on your operating system, you should be able to start connecting php scripts with mysql and using phpmyadmin to simplify the process.
There are plenty tutorials on getting php up and running with databases, just use google.
Good luck :)
Maybe these will be helpful:
http://community.linuxmint.com/tutorial/view/486 (for linux)
http://www.w3schools.com/php/php_mysql_intro.asp (once you get started)
HTML5 is just a static document, You cannot access a server-side databases from a web browser without server side scripts.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I am trying to connect to a Microsoft SQL Server 2008 database using sqlsrv_connect in PHP.
I've already installed, Microsoft SQL Server 2008 native client from http://www.microsoft.com/en-us/download/details.aspx?id=27596 (SQLSRV30.exe), since my php version is 5.4.3 and I am running with Thread Safety enabled.
I've also tried Connecting to an sql server database using php on windows.
I've configured everything accordingly, how it should be configured, but sqlsrv_connect is still giving me:
Fatal error: Call to undefined function sqlsrv_connect()
The thing is when I run php.exe -i in my command prompt, it shows that sqlsrv support is enabled: sqlsrv support => enabled, but it is not showing in phpinfo() although the sqlsrv extension is in my php ext directory, what could be wrong?
What am I doing wrong? I need help with this from people who might have had this connection problem before.
The mistake I made was that, I later learnt that there are three php.ini files that needs to be modified for the added extension to work.
The first is: wamp/bin/php/php.ini
The second: wamp/bin/apache/php.ini
The third: wamp/bin/php/phpForApache.ini
I didn't edit the last file, that was the problem. It works now.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have downloaded WAMP to try to learn PHP on, and am having trouble getting it to work as expected whenever trying to follow along in PHP tutorials.
Either what I get back in my browser is raw PHP (as shown below in "PHP Test 1"), or nothing at all (as shown below in "PHP Test 2"). I'm just trying to learn the basics of PHP, and am finding this to be very frustrating. Can anyone help? What do I need to do get PHP working, or what should I try?
Originally I was going to post screen shots to better describe the problem I'm having, as well as to better help others who are experiencing the same problem, but was not allowed to due to something about not having enough "points". Anyway, what I was originally trying to post can be found here:
https://sites.google.com/site/bluedog4678/
You need to start WAMPP then type this in the address bar: localhost/PHP_TEST_1.php.
You are currently opening a simple file without running WAMPP you need to run it through localhost.
You shouldn't access your files directly. Normally with simulated apache-servers you need to type in "localhost" to let it render correctly
EDIT
If you want to select a file it would be "localhost/"