I am using webmatrix and trying to connect to a local database in that which is SQL database . I have IIS and SQL Server installed on the computer . The database was created in webmatrix only .
Initially the error display was not on , I managed to do that by manipulating the php.ini file . After that I tried this script which is giving the following result .
<?php
if (function_exists('mssql_connect')){
echo "Okay, fn is there<br>------------------<br>";
} else {
echo "Hmmm .. fn is not even there<br>------------------<br>";
}
if(extension_loaded("mssql")) {
echo "MSSQL is Loaded<br>";
}
else {
echo "MSSQL not loaded<br>";
}
if(extension_loaded("msql")) {
echo "MSQL is Loaded<br>";
}
else {
echo "MSQL not loaded<br>";
}
echo '<br><br>';
$ext = get_loaded_extensions();
if(in_array('mssql', $ext))
echo 'u have mssql installed<br><br>';
else
echo 'u do NOT have mssql installed<br><br>';
?>
The result is :
Hmmm .. fn is not even there
MSSQL not loaded
MSQL not loaded
u do NOT have mssql installed
This is the command I was using to connect to mssql database
<?php
$con=mssql_connect('.\SQLEXPRESS','Shops_localdbU','thePass');
if($con) {
echo "success";
}
?>
and output was:
Fatal error: Call to undefined function mssql_connect() in C:\xampp\htdocs\sample.php on line 3
May be the functions are not installed on your server. If you have access to install them, then you can do that. If not, you cannot use these functions.
If you do have permission to modify the PHP configuration, start here:
http://www.php.net/manual/en/mssql.setup.php
Related
The following PHP win32_query_service_status works for querying the local machine, however we are attempting to perform this query on a remote machine within the same domain. We receive no errors however nothing is returned ideas?
$name = "spooler"
$machine = "remotemachine"
$status=win32_query_service_status($name, $machine);
echo "$name service is ";
if ($status["CurrentState"]==1) {echo "Stopped";}
else
if ($status["CurrentState"]==2) {echo "Starting";}
else
if ($status["CurrentState"]==3) {echo "Stopping";}
else
if ($status["CurrentState"]==4) {echo "Running";}
My first time to deploy matlab exec in php and i need ur help.
I have a matlab script compiled as sampleExe.exe (standalone app) with a single argument 'IdNo' to processes images. When i call it thru command line using sampleExe 2014000, the program runs and gives the desired output. However, I am having trouble when deploying/calling sampleExe.exe file from php as it gives me no output at all. :(
Here's the code i tried based on this: Call matlab exe from php is not working well
<?php
define("EVAL_IMAGE","sampleExe.exe");
$target=isset($_REQUEST['IdNo'])?trim($_REQUEST['IdNo']):"";
if($target==""){
echo "No folder name is passed";
exit();
}
passthru(EVAL_IMAGE." ".$target);
?>
Any help is very much appreciated. Btw, I tried running it in a localhost and sampleExe.exe is also save in c:/wamp/www
<?php
try {
define("EVAL_IMAGE","mainProg1.exe");
$target=isset($_REQUEST['IdNo'])?trim($_REQUEST['IdNo']):"";
if($target==""){
echo "No folder name is passed";
exit();
}
set_time_limit(300);
$return = exec(EVAL_IMAGE." ".$target);
echo "return = " .$return;
}catch (Exception $e) {
echo 'Message: ' .$e->getMessage();
}
exit(0); ?>
I want to execute a command on a remote machine and store the out of that command in a variable using php
Here is what i tried
$command = 'exec("whoami")';
$connection = ssh2_connect($ip,$port);
ssh2_auth_password($connection,$user,$pass);
$test = ssh2_shell($connection,$command);
echo $test;
According to me $test should output root
However nothing is return , I am sure i am missing something.....
php-pecl-ssh2 is already installed and no error is returned
I guess your command is incorrect :
$command = 'whoami';
And you should also add this 2 lines to the end to get your output :
if ( $connection = ssh2_connect($ip,$port) ) {
echo 'Error occured while connecting to server via ssh';
}
if (!ssh2_auth_password($connection,$user,$pass)) {
echo 'Error occured while authenticating via ssh';
}
if(!$test = ssh2_shell($connection,$command)){
echo 'Error occured while executing remote command via ssh';
} else {
stream_set_blocking($test, true);
echo stream_get_contents($test);
}
i running on my local system with ubuntu 12.04 64 bit , PHP 5.3.10 , gearman 1.1.5 .
following code
print gearman_version() . "\n";
throws php warning
PHP Warning: Module 'gearman' already loaded in Unknown on line 0
Also i built yii console app WorkerAdminCommand.php using
<?php
class WorkerAdminCommand extends CConsoleCommand {
public function run() {
$gmworker = new GearmanWorker();
$gmworker->addServer(); // also tried with $gmworker->addServer('127.0.0.1:4730');
$gmworker->addFunction("getMyFunc", array($this, "getMyFunc"));
print "Waiting for job...\n";
while ($gmworker->work()) {
if ($gmworker->returnCode() != GEARMAN_SUCCESS) {
echo "return_code: " . $gmworker->returnCode() . "\n";
break;
}
}
}
public function getMyFunc($job) {
echo "start \n";
// long task
echo "\n end \n";
}
}
?>
And AdminCommand.php
<?php
class AdminCommand extends CConsoleCommand {
public function run($args) {
$gmclient = new GearmanClient();
$gmclient->addServer();
echo "Sending job\n";
$data = $args[0];
$result = $gmclient->doBackground("getMyFunc", $data);
# Check for various return packets and errors.
switch ($gmclient->returnCode()) {
case GEARMAN_WORK_STATUS:
list($numerator, $denominator) = $gmclient->doStatus();
echo "Status: $numerator/$denominator complete\n";
break;
case GEARMAN_WORK_FAIL:
echo "Failed\n";
exit;
case GEARMAN_SUCCESS:
echo "Job process successfully\n";
break;
default:
echo "RET: " . $gmclient->returnCode() . "\n";
exit;
}
echo $result . PHP_EOL;
}
}
?>
run worker
php job_entry.php workeradmin
Waiting for job...
run client
php job_entry.php admin arg1
this gives me error
PHP Error[2]: GearmanClient::doBackground(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:430
can you try this
$gmworker->addServer('127.0.0.1','4730');
Type php --ini at your command prompt to see which php.ini your PHP CLI uses. Make sure Gearman is enabled in that php.ini. src Gearman , php extension problem : Class 'GearmanWorker' not found in .. using terminal but works on browser
I'm trying to roll a CMS website and I'm on 1and1 Internet's hosting. I'm trying to connect to my MySQL database and I get the following error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
After some frustration, I decided to check my include and it turns out that the following code is not including my connection variables file.
admin.php
<?php
include("connection.php");
$link = mysql_connect($connection_server, $connection_user, $connection_password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
connection.php
<?php
/* --------------------------------------
/
/ Bitachon.org Connection Variables
/
/ Created by: Moshe [Last Name]
/
/
/ Date: October 12, 2010
/
/
/ This file contains the connection
/ variable to connect to the MySQL
/ database that powers [site]
/
/ --------------------------------------*/
//Variable to confirm that the file has been included
$connnections_included = true;
/* --- Connection Variables ---*/
$connnection_server = "[server]";
$connection_database = "[db]";
$connection_user = "[username]";
$connection_password = "[password]";
?>
What's wrong?
The problem lies in your connection.php file, where there is a typo:
$connnection_server = "[server]";
// ^-- third n
Fixing that (along with the include() issue mentioned in Josh's answer) should resolve your problem.
Verify that you have the path set correctly
include("/path/to/connection.php");
Check permissions on connection.php, test to see if it's readable
$filename = 'connection.php';
if(is_readable($filename)) {
echo 'The file is readable';
} else {
echo 'The file is not readable';
}
Is the MySQL Database on the same server? AKA Localhost or another server?
Hard code the path
$pwd = `pwd`;
echo "PWD: ".$pwd."<br />"; // use just for testing
include($pwd."/connection.php");
EDIT:
Can you compare connection.php and admin.php
$filename = 'admin.php';
echo "Permissions: ".substr(sprintf("%o",fileperms($filename)),-4)."<br />";
echo "File Owner: ".fileowner($filename)."<br />";
echo "File Group: ".filegroup($filename)."<br />";
if(is_executable($filename)) {
echo ("$filename is executable<br />");
} else {
echo ("$filename is not executable<br />");
}
if(is_readable($filename)) {
echo "$filename is readable<br />";
} else {
echo "$filename is not readable<br />";
}
echo "Real Path: ".realpath($filename)."<br />";
$filename = 'connection.php';
echo "Permissions: ".substr(sprintf("%o",fileperms($filename)),-4)."<br />";
echo "File Owner: ".fileowner($filename)."<br />";
echo "File Group: ".filegroup($filename)."<br />";
if(is_executable($filename)) {
echo ("$filename is executable<br />");
} else {
echo ("$filename is not executable<br />");
}
if(is_readable($filename)) {
echo "$filename is readable";
} else {
echo "$filename is not readable";
}
echo "Real Path: ".realpath($filename)."<br />";
Put error_reporting(E_ALL); before
mysql_connect(). Do you get notices
about undefined variables? –
Lekensteyn
#Lekensteyn - Yes, I do. – Moshe
Put the following in config.php, before $connections_included.
global $connections_included, $connection_server, $connection_user, $connection_password;
It'll export those variables to the global scope.
After some frustration, I decided to check my include and it turns out that the following code is not including my connection variables file
To determine if this is really the case, try the following:
In connection.php add the line: die('This is connection.php.'); See if the script dies. If so, the file is being included.
Before $link = mysql_connect($connection_server, $connection_user, $connection_password) add: var_dump($connection_server) and see if the connection server is output when you run the script, or if something like "NULL" appears instead. If it's null, you know the variable isn't being set.
EDIT 1:
As per your message in chat:
You cannot include a remote file like using http://your.domain/connection.php. Well you can but as you saw, it won't work. include("http://your.domain/new/connection.php"); means "execute connection.php as a seperate request and include it's output".
You want:
include(dirname(__FILE__)."/connection.php");