I am still a programming newbie, please keep that in mind.
I installed SphinxSearch on Linux Mint. I followed instructions from a Digital Ocean tutorial. I created a configuration file (sphinx.conf) as follows:
source mySource{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = mypass
sql_db = test
sql_query = SELECT id, uname FROM users
sql_attr_uint = id
sql_attr_string = uname
sql_port = 3306
}
index test{
source = mySource
path = /var/lib/sphinxsearch/data
docinfo = extern
}
searchd{
listen = 9306:mysql41
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
read_timeout = 5
pid_file = /var/run/sphinxsearch/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
binlog_path = /var/lib/sphinxsearch/data
}
My PHP File
<?php
$conn = new mysqli('localhost','root','mypass','test',9306);
if($conn->connect_error){
die("Could not connect");
}else{
echo "You are connected!";
}
$query = $conn->query("SELECT * FROM test WHERE MATCH('hsmith')");
echo $query->error;
?>
PHP is throwing an error stating I am using a "Non-Object"
Any solution? Am I doing somethin entirely wrong?
Most likely the problem is in
$conn = new mysqli('localhost','root','mypass','test',9306);
As per http://php.net/manual/en/mysqli.construct.php when you pass 'localhost' in the 1st param mysqli tries to use unix socket, not a TCP socket and the port number therefore gets just ignored, i.e. you probably connect to your mysql instance instead of sphinx which then causes the problem you get.
Try:
$conn = new mysqli('127.0.0.1','','','test',9306);
instead.
Please also be aware that
echo $query->error;
is wrong since mysqli_result (http://php.net/manual/ru/class.mysqli-result.php) returned by query() does not have property 'error', you probably meant
echo $conn->error;
Related
I keep getting this error:
Warning: mysql_connect(): Unknown MySQL server host 'elephant' (1) 4
My ini file is this:
[Database]
DBHostName = "localhost"
DatabaseName = "elephant"
DBUserName = "elephant"
DBPassword = "practice"
[Config]
ConfigTableName = "stage2_config"
Skin="purple"
My file that reads the ini file and gives the error is this on the line with the double bold stars. I have no idea what is going on here and why it says the host isn't localhost.
<?php
$gv_SystemTest = "<h2>system.php has been included</h2>";
$gv_SystemFileInfo = pathinfo(__FILE__);
$gv_SystemDirectory = $gv_SystemFileInfo['dirname'] . '/';
$gv_SystemINIpath = $gv_SystemDirectory . '';
$gv_SiteGlobals = parse_ini_file($gv_SystemINIpath . $_SERVER['WIA_SYSTEM_INI'], true);
function echoContent($p_ContentID) {
global $gv_SiteGlobals;
$fv_dbLink = mysql_connect($gv_SiteGlobals['Database']['DBHostName'],
$gv_SiteGlobals['Database']['DBUserName'],
$gv_SiteGlobals['Database']['DBPassword']);
**mysql_connect($gv_SiteGlobals['Database']['DatabaseName']);**
$fv_TheQuery = "select *from wia_content where content_id = $p_ContentID";
The function mysql_connect does not allow to select a database as you tried on this line.
mysql_connect($gv_SiteGlobals['Database']['DatabaseName']);
To connect and select a database, you need to use the function mysql_select_db in addition to mysql_connect.
$link = mysql_connect('host','username','password');
$selected = mysql_select_db('database_name', $link);
http://php.net/manual/en/function.mysql-select-db.php
Dont use mysql use only mysqli or pdo
I think you want to select db
to select db you should be mysql_select_db()
mysql_select_db('foo', $link);
your error in this line
mysql_connect($gv_SiteGlobals['Database']['DatabaseName']);
it should be of the form
mysql_connect('localhost', 'mysql_user', 'mysql_password');
I've got a problem with sphinx configuration and php api use (on Windows 7).
I've configured the indexer : indexer --config sphinx.conf test1
And launch the service : searchd --install --config sphinx.conf
When I made a search with the cmd console, I found results, but... not with the php api.
Here the error : Query failed: failed to read searchd response (status=2613, ver=11830, len=774976045, read=70).
Here my conf file :
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source src1
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, UNIX_TIMESTAMP(addTime) AS addTime, title, brand, material, size, description, c.name as categoryName \
FROM test \
JOIN category c ON c.id = advert.categoryId
sql_attr_uint = id
sql_attr_timestamp = addTime
sql_query_info = SELECT * FROM test WHERE id=$id
}
index catalog
{
source = src1
path = C:\wamp\www\sphinx\catalog
docinfo = extern
charset_type = utf-8
min_word_len = 3
min_prefix_len = 0
min_infix_len = 3
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = C:\wamp\www\sphinx\log\searchd.log
query_log = C:\wamp\www\sphinx\log\query.log
read_timeout = 5
max_children = 30
pid_file = C:\wamp\www\sphinx\log\searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = C:\wamp\www\sphinx\data
}
The php file :
<?php
include('sphinxapi.php');
//Sphinx
$s = new SphinxClient;
$s->setServer("localhost", 3306);
$s->setMatchMode(SPH_MATCH_EXTENDED2);
$result = $s->query("#title jean");
if ($result['total'] > 0) {
foreach ($result['matches'] as $id => $otherStuff) {
echo $id;
}
} else {
echo "Query failed: " . $s->GetLastError() . ".\n";
}
?>
You are pointed in php script 3306 - it's port of mysql server in line:
$s->setServer("localhost", 3306);
try to point port 9312
Also try do following steps:
Remove installed windows service.
searchd --delete
Install windows service with full path to the configuration file
searchd --install --config fullPathToSphinx.conf
You need to run service manually or restart PC. To start manually service: run from command line program services.msc and find in the services list searchd and start it.
don't use "localhost" on Windows.
$s->setServer("127.0.0.1", 9312);
Can any one explain the connection string from the parameters below:
server IP : 192.168.137.4
Windows Authentication : Windows Authentication
UserName : DELL-M102Z\dell
Database : DataProd
Network Protocol : <default>
Product Name : Microsoft SQL Server Express Edition
Server Name : DELL-M102Z\SQLEXPRESS
Instance Name : SQLEXPRESS
Computer Name : DELL-M102Z
I tried:
$serverName = "DELL-M102Z\SQLEXPRESS"; //serverName\instanceName
$username = "DELL-M102Z\dell"; //serverName\instanceName
$conn = mssql_connect( $serverName,$username,'');
...but the result I got was:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: DELL-M102Z\SQLEXPRESS in C:...\index.php on line 17
Connection could not be established.
Can anyone tell me what is the problem here?
trying to follow this step:
http://michaelellerbeck.com/2010/03/31/cant-connect-remotely-to-sql-server-2008/
i know that i miss to activate sql browser service, and that's why i cannot connect by remote IP,
I got conclusion from that site and i must make sure that:
1. make sure you have allow network connection from sql server configuration tool
2. allow connection for this port in firewall
3. activate sql browser service
4. make sure port is listen as the the service provide
i got problem for no.3 and i'm stuck on it, this site solve the problem:
http://www.wikihow.com/Enable-Remote-Connections-SQL-2008-Express
<?php
$myServer = 'xxx.xxx.xxx.xxx:yyyy';
$myUser = 'sa';
$myPass = 'xxxxx';
$con = mssql_connect($myServer, $myUser, $myPass) or die("Could not connect to database: ".mssql_get_last_message());
if($con){
echo "connected";
}
// Select a database:
mssql_select_db('new')
or die('Could not select a database.');
// Example query: (TOP 10 equal LIMIT 0,10 in MySQL)
$SQL = "SELECT TOP 10 * FROM Table";
// Execute query:
$result = mssql_query($SQL)
or die('A error occured: ' . mysql_error());
// Get result count:
$count = mssql_num_rows($result);
print "Showing $count rows:<hr/>\n\n";
// Fetch rows:
while ($Row = mssql_fetch_assoc($result)) {
print $Row['BillNo'] . "\n";
}
mssql_close($con);
$myServer = 'IP_Address:PORT';
Here semicolon is need to ip and port
and
Mssql is enbaled at your cpanel
i am new to PDO.. i tried out some online tutorials and found some step-by-step guides. i am using WAMP, i created a database named "try" with table named "books".
Now in my index.php i wrote:
<?php
$host = "localhost:3306";
$db = "try";
$user = "clyde";
$pass = "moonfang";
$conn = new PDO("mysql:host=$host;dbname=$db",$user,$pass);
$sql = "SELECT * FROM books";
$q = $conn->query($sql) or die("failed!");
while($r = $q->fetch(PDO::FETCH_ASSOC)){
echo $r['title'];
}
?>
Now whenever i load localhost on my browser i see these errors;
i dont understand the problem.. :-(
According to several examples it seems that PDO prefers the host and the port in the dsn for itself:
$host = "localhost";
$port = 3307;
$conn = new PDO("mysql:host=$host;port=$port;dbname=$db",$user,$pass);
Here's the PHP manual for the PDO MySQL DSN. Note the "port" part.
The problem is that the target machine actively refused [the connection].
Therefore you have to check if usernames/passwords/access-rights to the database server are all OK; including IP/host and port/firewall settings.
Line 8 where error occurs is $q = $conn->query($sql) or die("failed!"); This line mixes mysql_ and PDO and is not required.
The code should look like
$sql = "SELECT * FROM books";
while($r = $sql->fetch(PDO::FETCH_ASSOC)){
echo $r['title'];
}
You should also incorporate PDO error handling
`
I'm having all sorts of trouble...
Here is the code I'm using:
$c = OCILogon('user', 'pass', 'host');
I get the following error:
PHP Warning: ocilogon(): ociopen_server: Error while trying to retrieve text for error ORA-12514 in D:\Inetpub\wwwroot**\oracle.php on line 26
Anyone know what the hell I'm doing wrong?
It's PHP4, IIS6 btw. I've tried this on PHP5, IIS7 as well, no luck.
Thanks for any help I can get... :(
You must have correctly configured TNSNAMES.ora file, where is stored information about connection to database. Oracle errorr ORA-12514 says:
TNS:listener does not currently know
of service requested in connect
descriptor
Function OCILogon have this syntax (I'am not PHP developer, so excuse me if I was not right):
resource oci_connect ( string
$username , string $password [,
string $connection_string [, string
$character_set [, int $session_mode
]]] )
In your example is on third position parametr "host". But manual says "connectin string".
This "connection string" must be coonfigured throught file $ORACLE_HOME/network/admin/tnsnames.ora file ($ORACLE_HOME is folder where is Oracle client installed).
TNSNAMES.ORA look like this(example):
TEST_DB = (DESCRIPTION =(ADDRESS_LIST
=(ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(Host =
127.0.0.1)(Port = 1521)))(CONNECT_DATA = (SID = TESTDB_SID)))
Instead:
$c = OCILogon('user', 'pass', 'host');
You should use:
$c = OCILogon('user', 'pass', 'TEST_DB');
...TEST_DB is service name from tnsnames.ora file
And yet for complementing (my file $ORACLE_HOME/network/admin/sqlnet.ora look like this):
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
NAME.DEFAULT_ZONE = world
NAMES.DEFAULT_DOMAIN = world
And finally PHP manual example (connection string can be inserted directly into variables in PHP):
<?php
$db ="(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = HOSTNAMEHERE)
(PORT = 1521)
)
(CONNECT_DATA = (SID = SIDNAMEHERE))
)";
$odbc = ocilogon ('user', 'pass', $db) or die( "Could not connect to Oracle database!") or die (ocierror());
?>
try using persistant connection oci_pconnect()... worked for me