Sublime Forum

Php script not working

#1

I’m trying Sublime Text 3 for the first time, and my commande :

This is what it looks like

<?php define('HOST', 'localhost'); define('dbname', 'siteweb'); define('USER', 'root'); define('PASS', ''); try{ $db = new PDO("mysql:host=" . HOST . ";dbname=" . DBNAME, USER, PASS); $db-> setAttribute(PDO:: ATTR_ERRORMODE, PDO::EXCEPTION) echo "Connecté > OK !"; } catch(PDOException $e){ echo $e; } Above what it should be : -> and : : aren't working If someone can help, it would be cool ! thx
0 Likes

#2

What exactly do you mean my “not working”?

1 Like

#3

My database.php is from Sublime text, i use Wamp.
I hope it helps

0 Likes

#4

Ahh OK. Unfortunately PHP isn’t one of the languages that I’m familiar with, so I don’t know why that particular problem might be occurring. Someone else more familiar with PHP may be able to help you diagnose what’s wrong, though.

This forum is primarily for support for Sublime Text and Sublime Merge; if nobody here can help you, you might have more luck if you post your question on Stack Overflow instead.

1 Like

#5

seems like your WAMP isn’t set up properly or isn’t being used as the php code isn’t being evaluated and is instead being parsed as HTML by the browser. Try adding a simple script like <?php php_info(); ?> to the www root and access it like http://localhost/test.php, and check the WAMP logs if it doesn’t work for clues why

2 Likes

#6

But I’m wondering about the line :
$db-> setAttribute(PDO:: ATTR_ERRORMODE, PDO::EXCEPTION)

Because the command -> and the four :: aren’t appearing in red as they should ( like in the example)
Sorry if I’m not getting the point, I’ll check for wamp whenever I can thx

0 Likes

#7

The syntax highlighting that you experience in Sublime is a combination of the color scheme that you’re using and the syntax definition that is in use.

So it’s entirely possible that the screen shot you’re looking at is using a syntax definition that knows more specifics about PHP than the one you’re currently using does, or it’s using a color scheme that has more enhanced colors than yours does, or both of those things at the same time.

One reason for that might be that it was taken with a different version of Sublime than the one that you’re currently using, for example.

In any case, probably the bigger issue at the moment is that your code isn’t doing what you expected it to do, because the way that it’s visualized in Sublime is just incidental.

As @kingkeith mentioned, it looks like in your second screen shot that you’re seeing your code when you view the page in the browser, instead of seeing the result of running it. If that’s the case, then your larger issue is that your web server isn’t properly running the code and is instead assuming that it’s a regular file.

I don’t work with PHP but as previously mentioned you should try with the smaller script file to see if that works, and ensure that the extension on the file is .php so that the server can tell what kind of file it is.

0 Likes

#8

it’s also maybe possible that this is relevant:

0 Likes

#9

This is what happend when i tried, maybe you got it @kingkeith , the syntax is correct but i got a wamp problem, if someone knows !

@OdatNurd I think that the video i’ve seen is quite old, maybe he used a different version, i hope so !

1 Like

#10

It should be phpinfo() and you should ask PHP questions on a PHP-related place, seriously.

0 Likes