I am attempting to follow this tutorial - https://developers.google.com/maps/articles/phpsqlajax_v3
I have a rather fundamental & simplistic question.
Using firefox, I can see this error when I load the html page with the php and javascript built in, as taken from the tutorial above.
TypeError: xml is null
The MySQL database I have is on my computer and is not hosted on the website in question. So, when I run the php script that exports the xml in the command line, I can see that it functions correctly.
I attempted to add my ip address to the phpsqlajax_dbinfo.php file, such that -
<?php
$username="";
$password="";
$database="";
$host="";
?>
But this results in a connection error.
What changes do I need to make for this to be able to reference the database on my computer, rather than one on the site?
EDIT
I have verified that the host, database, password and username fields are correct. I am able to run the phpsqlajax_genxml.php file from the command line.
If you run MySql on your computer use "localhost" as a server in phpsqlajax_dbinfo.php:
$server="localhost";
Your MySql DB is probably not set up to listen to your public IP, if you really want to use your IP you can add it to my.cnf, but I would really recommend using localhost:
bind-address = your_ip
Related
I am in the process of making a chat app. I create accounts, login, select, view and do more already with PHP MySQL. And I am beginning to get into the Instant Messaging side of things.
I am using NodeJS and SocketIO for this and I have got the demo and such running but when attempting to integrate it into my current PHP stack it fails the mysql calls. I believe the problem is the networking but I could be wrong. Some direction or advice would be much appreciated.
User hits index.html > authenticate.js(ajax) > Sessions.php > Redirect to login or load page with data. However the echo data back:
echo "<script type='text/javascript'>
$('#detailsnote').hide();
$('#edituserimage').attr('src','$Image');
$('#editusername').val('$Username');
$('#editfirstname').val('$Firstname');
$('#editlastname').val('$Lastname');
$('#editnickname').val('$Nickname');
$('#editposition').val('$Position');
$('#editmobile').val('$Mobile');
$('#editdob').val('$DOB');
$('#editemail').val('$Email');
$('#userid').val('$UserID');
</script>";
Gets put in a div that handles that data, but instead, it is showing that echo as text.
I could be entirely wrong and can't mix PHP and NODEJS with MYSQL but I thought it would work. So again, any advice is welcome. Even if it is "Re-write the whole thing in NodeJS"
You can't combine php code with node JS code. Node does not understand the echo keyboard.
you have to use the redis for this. And use redis pub/sub method for it. Like make a channel in redis and publish data through php and subscribe(broadcast) redis data via nodejs and send capture it on browser through (socket.io)
I am trying to implement Google Leaderboard for my games.
So I have downloaded sample scripts from the following URL: https://github.com/playgameservices/web-basic-samples
and put it in the web server:
E:\wamp\www\sugumar\web-basic-samples-master
and in the browser I tried
http://localhost/sugumar/web-basic-samples-master/type-a-number-js/index.html
but it showed the following error
Not Found
The requested URL
/sugumar/web-basic-samples-master/type-a-number-js/index.html was not
found on this server.
so I checked the file permissions for the folder web-basic-samples-master (I have so many projects running under sugumar folder so no problem with that folder permission).
It was in read only mode, so I unchecked the readonly and clicked on apply and on the next screen I clicked ok for "Apply changes to this folder, subfolders files" and then I clicked on ok, and then run the following url again
http://localhost/sugumar/web-basic-samples-master/type-a-number-js/index.html
but it still shows the same problem:
Not Found
The requested URL
/sugumar/web-basic-samples-master/type-a-number-js/index.html was not
found on this server.
It seems you've skipped the entire Running the sample application guide accompanying the code sample:
To run this sample application in your own environment, perform the
following steps:
1.Get the latest Google APIs Client Library for PHP and extract it into your server directory.
- We recommend you retrieve this using git, to ensure you always have the latest version. (e.g. git clone
https://github.com/google/google-api-php-client)
- Alternately, you can get the gzip file from the downloads page. Please make sure you download version 0.6.2 or later (updated June 3,
2013), as the GameService contrib file does not exist in earlier
versions.
2.This application assumes you have PHP/MySQL already running on your server. Create a users table with the following setup:
CREATE TABLE IF NOT EXISTS `users` ( `temp_key` varchar(128) NOT
> NULL, `user_id` varchar(64) NOT NULL, `bearer_token`
> varchar(1024) NOT NULL, `last_modified` timestamp NOT NULL DEFAULT
> CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY
> (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Create your own application in the Play Console, as described in the Create Client IDs portion of the documentation. Make sure you
follow the "Web" instructions for creating your Client ID and linking
your application.
If you've already set up your own version of the Type-a-Number sample
application, you can repurpose that application here. Either create a
new linked application (which will give you a new client ID), or add
your test server to your list of Javascript Origins in the APIs
Console (which will let you re-use your current client ID)
When you link your Web application, ensure the hostname matches the server from which you'll be testing your application. (e.g.
http://localhost/ or https://www.mytestserver.com). Also, make sure
that you have the right protocol (http vs. https)
Make a note of your Client ID and Client Secret as described in the documentation
Create a Leaderboard as described in the Leaderbords documentation. Give it a creative name like "High scores".
Once that's done, you'll want to replace the following constants defined in the SampleAppConstants.ini file.
In the api section, replace the following: clientId (Replace this with
your OAuth2.0 Client ID) clientSecret (Replace this with your OAuth2.0
Client secret) In the db section, replace the following: user (Replace
this with your MySQL username) pass (Replace this with your MySQL
password) host (Replace this with your MySQL hostname) name (Replace
this with the name of the MySQL database you're using.) In the game
section, replace the following: leaderboardId (Replace this with the
ID of the leaderboard you created in the previous step.)
Move your AppConstants.ini file outside of your htdocs tree. This contains sensitive information and it shouldn't be located anywhere
where it could accidentally be displayed to the user.
Update the constructor in your GameHandler file to point to the new location of AppConstants.ini.
That's it! Your application should be ready to run!
I've setup a physical mac computer to be a MySQL server. It works perfectly well if I access it remotely on the internet if I access it through the Terminal. Edit: I now realise this is on the local network only. So I'm now setting up a static IP and will have to post another question on that if I get stuck
But I'd love to solve why it someone doesn't work if I connect with javascript, such as in GoogleSpreadsheets or any related add-ons in GoogleSpreadsheets (which are also written on Javascript I think).
I can use any of those javascript approaches to connect to other databases which I have access to, but I'd like to find out why I can't connect to mine in particular and if there is anything I can change? Thanks.
I setup a MySQL server on computer A (Mac OS X Yosemite). I can connect fine if I use do the following in bash on computer B (Mac OS El Capitan) and then get whatever output I need from MySQL.
$ # in bash, change path to ensure SQL runs
$ export PATH=$PATH:/usr/local/mysql/bin/
$ # start sql and run a query
$ mysql -u test -pXXXXX -h 192.168.XXX.XX sakila # replace X's with real credentials, where -p is for the password and -h is for the IP address.
$ mysql> SHOW TABLES;
$ mysql> #... output is good
$ mysql> exit;
$
If I run the same credentials in Google Spreadsheets script editor, I get an error on the last line saying that either my connection string, user or password are not correct. See script below.
// attempt to access SQL data using javascript on https://script.google.com
function Drive() {
var ServerIP = '192.168.XXX.XX'; // IP address of the server. replace with real IP
var SQL_Port = '3306'; // port number
var SQL_Usr = 'test'; // name of user
var SQL_Pwd = 'xxxxx'; // password of user. replace with real password
var SQL_DB = 'sakila'; // name of sample database downloaded from MySQL Workbench documentation.
var connectorInstance = 'jdbc:mysql://' + ServerIP +':' + SQL_Port;
var ConnectString = connectorInstance + '/' + SQL_DB;
var conn = Jdbc.getConnection(ConnectString, SQL_Usr, SQL_Pwd); // error on this line
}
My javascript, my syntax is definitely correct, since if I swop in the credentials for another online database then the error disappears. Similarly, I tried 4 different Google Spreadsheets add-ons which are available when you search "SQL" in the add-on store; those work with all databases I tried but not my own.
And my own server's credentials and authorisation should be working correctly, since I can connect using bash as shown at the top.
Is there some security option setup on the other databases in the server or in their internet connection which means javascript will connect on theirs and not mine? Is there something I missed?
My alternatives would be to only access the server with bash (not good when I am building a Spreadsheet-based front-end), or to host the server online, which would involve some costs.
Would an SSH connection help at all? I haven't used one before. Any help would be appreciated.
Steps I've tried
I started off setting up MySQL Workbench with a config file as -"etc/my.cnf".
I set "skip-networking" off.
I made sure "bind_address" was off and also tried variations since as "0.0.0.0", "*" and "%".
I followed a lesson on setting up javascript code for Google scripts and granted sufficent user account details on location "%" (yes I know that's not secure but this is a small test db).
I've tried playing around with other Options File preferences under Networking or other section, but they either have no effect or the server fails to restart successfully with those applied.
Before testing my DB connection, I make sure I restart my SQL server to ensure option and user changes are applied.
I've checked StackOverflow to see who else is asking about remote databases, javascript or connection strings. No one else seems to have my exact issue.
I've tried using the host's name "Servers-Macbook-Air.local" in place of IP, again that works in bash but NOT in Javascript still. Also if I use IP or hostname for another database, that works.
I did some research after Hardy's comment - I think it is the private IP restricting me. I had only tried with both laptops in Wifi range.
http://www.gohacking.com/private-and-public-ip-addresses/
Say for example, if a network X consists of 10 computers, each of them can be given an IP starting from 192.168.1.1 to 192.168.1.10. Unlike the public IP, the administrator of the private network is free to assign an IP address of his own choice (provided the IP number falls in the private IP address range as mentioned above).
Devices with private IP addresses cannot connect directly to the Internet. Likewise, computers outside the local network cannot connect directly to a device with a private IP.
Your problem is you are trying to your local IP address of 192.168.xxx.xxx
You can not do that from the internet. As a matter of fact, that IP address only exists within your network. You and I could both have the IP of 192.168.1.10. Most off-the-shelf routers create networks that begin with 192.168.1.1 (which is probably where you can access your firewall).
The only way this could work is if you used your public IP address and you have the port you are looking for configured to point to your machine. This would typically require some Port Forwarding or Firewall configuration.
You can check your public IP with sites like http://www.ipchicken.com
What I want to do is simple in theory, but I cannot quite get it to work.
I wrote a simple node.js script that uses the request package to asynchronously fetch some data, parse it, and spit it out as html. I wanted to integrate this script in my client's php and apache based website which is on a shared host, and ran into some snags:
There is no mod_proxy, so I can't simply run my node script as a server and proxy through Apache
I don't want to run node on port 80 and proxy to apache from node. It's just way too much overkill for what I need to do, and would introduce too many headaches for me. My particular shared host is known to have trouble keeping node server instances up, and I can't justify potential downtime just for this script to run.
I tried the node-cgi package but it didn't work for me. I got errors about internal node methods not existing, I think this package is just out of date.
So what I have landed on is trying to simply call node from PHP. My whole index.php file is:
<?php
header("Content-Type: text/html");
exec("node beerlist.nd", $output);
echo implode('', $output);
When I execute php index.php on the command line, I get my expected output, however, when I try to access this from the browser, I get nothing ie Content-Length: 0. Why?
I thought maybe it had to do with the async nature of my node script but it seems like the process stays alive until it finishes all the async calls. So shouldn't my php snippet send the output to the browser without any trouble? What am I missing here?
Edit: This gist of my node script is
var req = require('request')
req("http://mywebsite.com", function(err, resp, body) {
var output = // pull some interesting pieces out of the whole body
console.log(output);
});
The generation of my output variable is not central to the issue here. The relevant parts are that I use request to make an asynchronous call and use console.log to output my results... maybe this is a problem?
I suppose Apache user doesn't know what node command is. If I'm right try to write in php file:
<full path to node> beerlist.nd
instead of
node beerlist.nd
To get full path to node run in terminal which node
I want to build an entire web app using only Javascript and MYSQL . How can I go about this if it's possible.
Try something like Jaxer, which will allow you to execute JavaScript on the Web Server and query databases.
Here are some syntax examples and usages:
Database, file, and socket access from JavaScript
alt text http://jaxer.org/images/Picture+4_0.png
Easily create RESTful JSON data services
alt text http://jaxer.org/images/Picture+6.png
Directly call server-side functions from the browser
alt text http://jaxer.org/images/Picture+2_0.png
You can do it with Jaxer. There are some screencasts that'll get you started. Also check out project Phobos. Jaxer integrates nicely in Aptana studio, Phobos in Netbeans.
If you can run javascript on the server, you can build a web-application with it (without the need for any other language like PHP etc.). Search the web for 'connection string mysql' to find out how to connect to your mySQL database and use ADO/ODBC. You'll need the MySQL ODBC-connector on the MySQL server.
Here's an example database connection (where MySQL server resides on the same server as the web server):
function connectDB()
{
var connectStr = "DRIVER={MySQL ODBC 3.51 Driver}; " +
"SERVER=localhost; " +
"PORT=[MySQL server port];" +
"DATABASE=[your database]; " +
"UID=[username];PWD=[password];" +
"OPTION=3",
conection = Server.CreateObject("ADODB.Connection");
//ERRID=>lib::connectDB::open
try {connection.Open(connectStr) }
catch(e) {errAlert(e,'rs::connectDB','connection failed',1) }
return connection;
}
(Where errAlert is a custom function to return the error)
You could write your application entirely in client side javascript with AJAX / REST calls to your database server - using something like CloudKit on your server (or CouchDB, which features a native JSON HTTP interface). On the client side, Dojo or YUI abstract out a great deal of the IO handling…
It's quite possible to write a web application using only javascript. One the key benefits of that is that since all code runs locally, you can make an application which doesn't require online connectivity.
The main detractor though, is that you can't hook it up to a database. But there are alternative data storage hacks you can use.
One example of such a javascript application is TiddlyWiki which is a personal wiki, contained in a single html file. The javascript application rewrites that html file, so you can carry it with you on a USB-drive or something.
You could look at triplify which should expose your database as json and rdf. I haven't actually used this but I would imagine that would let you bypass writing any server side js and talk to the database directly in a language javascript understands, using an ajax request and json.
You can build client-side applications in javascript, with an embedded database. HTML 5 has support for databases, and a couple of browsers have already implemented this part of the spec (safari, firefox with the gears plugin).
But this is only for clientside usage. You wont be able to share the database with other users. Also you can select which database you want to use. I think gears uses sqlite.
You will not be able to use Javascript and MYSQL without using something such as PHP on the server side to bridge the gap between the database and the Javascript on the client side.
Edit: I may be wrong, however I have no idea how you would run Javascript on the server side.